package com.yanchangapp.adapter;

import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yanchangapp.R;
import com.yanchangapp.commom.OrderStatus;
import com.yanchangapp.model.bean.PsOrderListBean;
import com.zxl.baselib.util.formatter.BigDecimalUtils;
import com.zxl.baselib.util.time.TimeUtil;
import com.zxl.baselib.util.ui.ResHelper;

import java.util.List;

/**
 * Created by apple on 2019-08-05.
 * description:
 */
public class PsOrderAdapter extends BaseQuickAdapter<PsOrderListBean, BaseViewHolder> {

    public PsOrderAdapter(int layoutResId, @Nullable List<PsOrderListBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, PsOrderListBean psListBean) {
        // 依据标签,设置背景...
        TextView tvTag =  baseViewHolder.getView(R.id.tvTag);
        tvTag.setText(psListBean.getStatusName());
        if (OrderStatus.ALREADY_PASS.getStatus().equals(psListBean.getStatus())){
            tvTag.setBackground(ResHelper.getDrawable(R.drawable.tag_order_pass));
        }else if (OrderStatus.ALREADY_REJECTED.getStatus().equals(psListBean.getStatus())){
            tvTag.setBackground(ResHelper.getDrawable(R.drawable.tag_order_reject));
        }else if (OrderStatus.WAIT_SUBMIT.getStatus().equals(psListBean.getStatus())){
            tvTag.setBackground(ResHelper.getDrawable(R.drawable.tag_order_submit));
        }else {
            tvTag.setBackground(ResHelper.getDrawable(R.drawable.tag_order_default));
        }
        baseViewHolder.setText(R.id.tvOrderNo,ResHelper.getString(R.string.order_no,psListBean.getOrderNo()));
        baseViewHolder.setText(R.id.tvSupplierName,ResHelper.getString(R.string.order_supplier_name,psListBean.getSupplierName()));
        baseViewHolder.setText(R.id.tvDownTime,ResHelper.getString(R.string.down_order_time, TimeUtil.getDayTime(psListBean.getOrderDate())));
        baseViewHolder.setText(R.id.tvDownSum,ResHelper.getString(R.string.down_order_sum,
                String.valueOf(psListBean.getItemNum()), BigDecimalUtils.keep2Decimal(psListBean.getTotalMoney())));
        RecyclerView recyclerView =  baseViewHolder.getView(R.id.recycleList);
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext,LinearLayoutManager.VERTICAL,false));
        recyclerView.setAdapter(new ProductHAdapter(R.layout.item_inner_product_text,psListBean.getProducts()));

        LinearLayout llBottomSubmit =  baseViewHolder.getView(R.id.llBottomSubmit);
        TextView tvDelete =  baseViewHolder.getView(R.id.tvDelete);
        TextView tvModify = baseViewHolder.getView(R.id.tvModify);
        TextView tvSubmit = baseViewHolder.getView(R.id.tvSubmit);
        if (psListBean.isFlag()){
            llBottomSubmit.setVisibility(View.VISIBLE);
            // 通过和已驳回状态
            if (OrderStatus.WAIT_SUBMIT.getStatus().equals(psListBean.getStatus()) ||
            OrderStatus.ALREADY_REJECTED.getStatus().equals(psListBean.getStatus())){
                tvDelete.setVisibility(View.VISIBLE);
                tvModify.setVisibility(View.VISIBLE);
                // 如果不等于...
                if (!OrderStatus.ALREADY_REJECTED.getStatus().equals(psListBean.getStatus())){
                    tvSubmit.setVisibility(View.VISIBLE);
                }else {
                    tvSubmit.setVisibility(View.GONE);
                }
            }else {
                tvDelete.setVisibility(View.GONE);
                tvModify.setVisibility(View.GONE);
                tvSubmit.setVisibility(View.GONE);
            }
        }else {
            llBottomSubmit.setVisibility(View.GONE);
        }
        // 添加列表的点击事件....
        baseViewHolder.addOnClickListener(R.id.tvDelete)
                .addOnClickListener(R.id.tvModify)
                .addOnClickListener(R.id.tvSubmit);
    }
}
